<template>
    <div style="padding:20px">
        <div style="display: flex;justify-content: space-between;align-items: center">
            <h1 class="title">知识库列表</h1>
            <el-button type="primary" @click="drawerVisible = true"><el-icon>
                    <Plus />
                </el-icon>创建知识库</el-button>
        </div>
        <div>

            <el-table :data="kdbList">
                <template #empty>
                    <el-empty description="暂无知识库，快去创建吧~" />
                </template>
                <el-table-column prop="id" label="ID" />
                <el-table-column prop="name" label="知识库名称" />
                <el-table-column prop="count" label="知识数量" />
                <el-table-column fixed="right" label="操作" min-width="120">
                    <template #default="scope">
                        <el-button link type="primary" size="small"
                            @click="() => { this.$router.push(`/kdbInfo/${scope.row.id}`) }">
                            详情
                        </el-button>
                        <el-button link type="primary" size="small" @click="deleteKDB(scope.row.id)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
    </div>

    <el-drawer v-model="drawerVisible" title="新增知识库" :direction="direction" :before-close="handleClose">
        <el-form label-position="top" label-width="auto">
            <el-form-item label="知识库名称">
                <el-input v-model="form.title" placeholder="请输入知识库名称"  @keyup.enter.native="createKDB"></el-input>
               
            </el-form-item>
        </el-form>

        <template #footer>
            <div style="flex: auto">
                <el-button @click="drawerVisible = false">取消</el-button>
                <el-button type="primary" @click="createKDB">确认</el-button>
            </div>
        </template>
    </el-drawer>
</template>
<script>
import { fa } from 'element-plus/es/locale/index.mjs';
import { POST } from '../../util/axios.js'
export default {
    data() {
        return {
            kdbList: [],
            drawerVisible: false,
            form: { title: "",id:0 }
        }
    },
    methods: {
        async getKDBList() {
            let rs = await POST("/kdb/getKDBList", "POST", {}, false)
            console.log("rs:>>:", rs)
            this.kdbList = rs.data
        },
        async createKDB() {
            let rs = await POST("/kdb/createKDB", "POST", this.form, true)
            console.log("rs:>>:", rs)
            this.drawerVisible = false
            this.getKDBList()
            // this.kdbList = rs.data
        },
        async deleteKDB(id) {

            let rs = await POST("/kdb/deleteKDB", "POST", {id:id}, true)
            console.log("rs:>>:", rs)
            this.getKDBList()


        }
    },
    mounted() {
        this.getKDBList()
    }
}
</script>
<style></style>